package com.ruoyi.leader.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.leader.domain.TGroupLeader;
import com.ruoyi.leader.service.ITGroupLeaderService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 团长信息Controller
 * 
 * @author zzy
 * @date 2025-08-17
 */
@RestController
@RequestMapping("/leader")
public class TGroupLeaderController extends BaseController
{
    @Autowired
    private ITGroupLeaderService tGroupLeaderService;

    /**
     * 查询团长信息列表
     */
    @RequiresPermissions("leader:leader:list")
    @GetMapping("/list")
    public TableDataInfo list(TGroupLeader tGroupLeader)
    {
        startPage();
        List<TGroupLeader> list = tGroupLeaderService.selectTGroupLeaderList(tGroupLeader);
        return getDataTable(list);
    }

    /**
     * 导出团长信息列表
     */
    @RequiresPermissions("leader:leader:export")
    @Log(title = "团长信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TGroupLeader tGroupLeader)
    {
        List<TGroupLeader> list = tGroupLeaderService.selectTGroupLeaderList(tGroupLeader);
        ExcelUtil<TGroupLeader> util = new ExcelUtil<TGroupLeader>(TGroupLeader.class);
        util.exportExcel(response, list, "团长信息数据");
    }

    /**
     * 获取团长信息详细信息
     */
    @RequiresPermissions("leader:leader:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tGroupLeaderService.selectTGroupLeaderById(id));
    }

    /**
     * 新增团长信息
     */
    @RequiresPermissions("leader:leader:add")
    @Log(title = "团长信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TGroupLeader tGroupLeader)
    {
        return toAjax(tGroupLeaderService.insertTGroupLeader(tGroupLeader));
    }

    /**
     * 修改团长信息
     */
    @RequiresPermissions("leader:leader:edit")
    @Log(title = "团长信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TGroupLeader tGroupLeader)
    {
        return toAjax(tGroupLeaderService.updateTGroupLeader(tGroupLeader));
    }

    /**
     * 删除团长信息
     */
    @RequiresPermissions("leader:leader:remove")
    @Log(title = "团长信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tGroupLeaderService.deleteTGroupLeaderByIds(ids));
    }
}
